home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / c / agl103p.lha / src / agl / RCS / mice.c,v < prev    next >
Encoding:
Text File  |  1994-12-09  |  7.8 KB  |  457 lines

  1. head    1.2;
  2. branch    1.2.1.99;
  3. access;
  4. symbols;
  5. locks; strict;
  6. comment    @ * @;
  7.  
  8.  
  9. 1.2
  10. date    93.01.27.22.02.27;    author jason;    state Exp;
  11. branches
  12.     1.2.1.1;
  13. next    ;
  14.  
  15. 1.2.1.1
  16. date    94.03.29.05.41.32;    author jason;    state Exp;
  17. branches;
  18. next    1.2.1.2;
  19.  
  20. 1.2.1.2
  21. date    94.11.16.06.25.25;    author jason;    state Exp;
  22. branches;
  23. next    1.2.1.3;
  24.  
  25. 1.2.1.3
  26. date    94.12.09.05.29.56;    author jason;    state Exp;
  27. branches;
  28. next    ;
  29.  
  30.  
  31. desc
  32. @second mouse interface
  33. @
  34.  
  35.  
  36. 1.2
  37. log
  38. @Initial RCS Version
  39. @
  40. text
  41. @#include"agl.h"
  42.  
  43. struct MsgPort *GameMP;
  44. struct IOStdReq *GameIO;
  45. struct InputEvent *GameEV;
  46. struct IntuiMessage *GameMS;
  47. BYTE GameEventBuffer[sizeof(struct InputEvent)];
  48.  
  49. struct GamePortTrigger GameTR=
  50.     {
  51.     GPTF_DOWNKEYS|GPTF_UPKEYS,        /* transition trigger */
  52.     300,                            /* seconds * 60Hz (time per auto event) */
  53.     1,1                                /* delta mouse trigger */
  54.     };
  55.  
  56.  
  57. /******************************************************************************
  58. long    start_gameport(void)
  59.  
  60.     returns TRUE if successful
  61.  
  62. ******************************************************************************/
  63. /*PROTOTYPE*/
  64. long start_gameport(void)
  65.     {
  66.     GameEV=(struct InputEvent *)GameEventBuffer;
  67.  
  68.     if((GameMP=CreatePort("RKM_game_port",0)))
  69. /*     if((GameMP=CreatePort(NULL,0))) */
  70.         {
  71.         if(GameIO=(struct IOStdReq *)CreateExtIO(GameMP,sizeof(struct IOStdReq)))
  72. /*         if(GameIO=(struct IOStdReq *)CreateStdIO(GameMP)) */
  73.             {
  74.             if(!OpenDevice("gameport.device",1,(struct IORequest *)GameIO,0))
  75.                 {
  76.                 if(set_controller_type((BYTE)GPCT_MOUSE))
  77.                     {
  78.                     set_trigger_conditions();
  79.  
  80.                     flush_buffer();
  81.  
  82.                     printf("gameport started\n");
  83.                     return TRUE;
  84.                     }
  85.                 else
  86.                     GL_error("can't set game port");
  87.  
  88.                 CloseDevice((struct IORequest *)GameIO);
  89.                 }
  90.             else
  91.                 GL_error("can't open game port");
  92.  
  93.             DeleteExtIO((struct IORequest *)GameIO);
  94.             }
  95.         else
  96.             GL_error("can't create game IO");
  97.  
  98.         DeletePort(GameMP);
  99.         }
  100.     else
  101.         GL_error("can't create game port");
  102.  
  103.     return FALSE;
  104.     }
  105.  
  106.  
  107. /******************************************************************************
  108. void    stop_gameport(void)
  109.  
  110. ******************************************************************************/
  111. /*PROTOTYPE*/
  112. void stop_gameport(void)
  113.     {
  114.     printf("stop gameport\n");
  115.  
  116.     free_gameport();
  117.  
  118.     if(!(CheckIO((struct IORequest *)GameIO)))
  119.         AbortIO((struct IORequest *)GameIO);    /* ask device to abort request, if pending */
  120.  
  121.     WaitIO((struct IORequest *)GameIO);            /* wait for abort, then clean up */
  122.     CloseDevice((struct IORequest *)GameIO);
  123.     DeleteExtIO((struct IORequest *)GameIO);
  124.     DeletePort(GameMP);
  125.  
  126.     printf(" stopped\n");
  127.     }
  128.  
  129.  
  130. /******************************************************************************
  131. void    send_read_request(void)
  132.  
  133. ******************************************************************************/
  134. /*PROTOTYPE*/
  135. void send_read_request(void)
  136.     {
  137.     GameIO->io_Command=GPD_READEVENT;
  138.     GameIO->io_Flags=0;
  139.     GameIO->io_Length=sizeof(struct InputEvent);
  140.     GameIO->io_Data=(APTR)&GameEventBuffer;
  141.     SendIO((struct IORequest *)GameIO);
  142.     }
  143.  
  144.  
  145. /******************************************************************************
  146. void    set_trigger_conditions(void)
  147.  
  148. ******************************************************************************/
  149. /*PROTOTYPE*/
  150. void set_trigger_conditions(void)
  151.     {
  152.     GameIO->io_Command=GPD_SETTRIGGER;
  153.     GameIO->io_Flags=IOF_QUICK;
  154.     GameIO->io_Data=(APTR)&GameTR;
  155.     GameIO->io_Length=sizeof(struct GamePortTrigger);
  156.     DoIO((struct IORequest *)GameIO);
  157.     }
  158.  
  159.  
  160. /******************************************************************************
  161. long    set_controller_type(BYTE type)
  162.  
  163. ******************************************************************************/
  164. /*PROTOTYPE*/
  165. long set_controller_type(BYTE type)
  166.     {
  167.     long success=FALSE;
  168.     BYTE controller_type=0;
  169.  
  170.     Forbid();                                /* start critical section */
  171.  
  172.     GameIO->io_Command=GPD_ASKCTYPE;        /* inquire current status */
  173.     GameIO->io_Length=1;
  174.     GameIO->io_Flags=IOF_QUICK;
  175.     GameIO->io_Data=(APTR)&controller_type;    /* put answer here */
  176.     DoIO((struct IORequest *)GameIO);
  177.  
  178.     if(controller_type==GPCT_NOCONTROLLER)    /* if not in use */
  179.         {
  180.         GameIO->io_Command=GPD_SETCTYPE;
  181.         GameIO->io_Length=1;
  182.         GameIO->io_Flags=IOF_QUICK;
  183.         GameIO->io_Data=(APTR)&type;
  184.         DoIO((struct IORequest *)GameIO);
  185.  
  186.         success=TRUE;
  187.         }
  188.  
  189.     Permit();                                /* end critcal section */
  190.  
  191.     return success;
  192.     }
  193.  
  194.  
  195. /******************************************************************************
  196. void    free_gameport(void)
  197.  
  198. ******************************************************************************/
  199. /*PROTOTYPE*/
  200. void free_gameport(void)
  201.     {
  202.     BYTE type=GPCT_NOCONTROLLER;
  203.  
  204.     GameIO->io_Command=GPD_SETCTYPE;
  205.     GameIO->io_Flags=IOF_QUICK;
  206.     GameIO->io_Length=1;
  207.     GameIO->io_Data=(APTR)&type;
  208.     DoIO((struct IORequest *)GameIO);
  209.     }
  210.  
  211.  
  212. /******************************************************************************
  213. void    flush_buffer(void)
  214.  
  215. ******************************************************************************/
  216. /*PROTOTYPE*/
  217. void flush_buffer(void)
  218.     {
  219.     GameIO->io_Command=CMD_CLEAR;
  220.     GameIO->io_Flags=IOF_QUICK;
  221.     GameIO->io_Data=NULL;
  222.     GameIO->io_Length=0;
  223.     DoIO((struct IORequest *)GameIO);
  224.     }
  225.  
  226.  
  227. /******************************************************************************
  228. long    gameport_event(long *device,short *state,short *dx,short *dy)
  229.  
  230.     only affected values are changed
  231.  
  232.     returns code (FALSE if no message)
  233.  
  234. ******************************************************************************/
  235. /*PROTOTYPE*/
  236. long gameport_event(long *device,short *state,short *dx,short *dy)
  237.     {
  238.     long code;
  239.  
  240.     *device=NULL;
  241.     *state=0;
  242.     *dx=0;
  243.     *dy=0;
  244.  
  245.     GameMS=(struct IntuiMessage *)GetMsg(GameMP);        /* try first without asking */
  246.  
  247.     if(GameMS==NULL)
  248.         {
  249.         send_read_request();                            /* send request */
  250.  
  251.         GameMS=(struct IntuiMessage *)GetMsg(GameMP);    /* try again */
  252.  
  253.         if(GameMS==NULL)                                /* still no message */
  254.             {
  255. /*             printf("gameport_event() no message\n"); */
  256.             return FALSE;                                /* give up for now */
  257.             }
  258.         }
  259.  
  260.     code=GameEV->ie_Code;
  261.     switch(code)
  262.         {
  263.         case IECODE_LBUTTON:
  264.             printf("gameport_event() left down\n");
  265.             *device=BPAD1;
  266.             *state=TRUE;
  267.             break;
  268.         case IECODE_LBUTTON+IECODE_UP_PREFIX:
  269.             printf("gameport_event() left up\n");
  270.             *device=BPAD1;
  271.             *state=FALSE;
  272.             break;
  273.         case IECODE_MBUTTON:
  274.             printf("gameport_event() middle down\n");
  275.             *device=BPAD2;
  276.             *state=TRUE;
  277.             break;
  278.         case IECODE_MBUTTON+IECODE_UP_PREFIX:
  279.             printf("gameport_event() middle up\n");
  280.             *device=BPAD2;
  281.             *state=FALSE;
  282.             break;
  283.         case IECODE_RBUTTON:
  284.             printf("gameport_event() right down\n");
  285.             *device=BPAD3;
  286.             *state=TRUE;
  287.             break;
  288.         case IECODE_RBUTTON+IECODE_UP_PREFIX:
  289.             printf("gameport_event() right up\n");
  290.             *device=BPAD3;
  291.             *state=FALSE;
  292.             break;
  293.         case IECODE_NOBUTTON:
  294. /*             printf("gameport_event() no button\n"); */
  295.             break;
  296.         default:
  297.             printf("gameport_event() default\n");
  298.             return FALSE;
  299.             break;
  300.         }
  301.  
  302.     *dx=  GameEV->ie_X;
  303.     *dy= -GameEV->ie_Y;
  304.  
  305. /*     printf("gameport_event() code=%d %2d,%2d\n",code,GameEV->ie_X,GameEV->ie_Y); */
  306.  
  307. /*     ReplyMsg((struct Message *)GameMS); */
  308.  
  309.     return code;
  310.     }
  311. @
  312.  
  313.  
  314. 1.2.1.1
  315. log
  316. @Added RCS Header
  317. @
  318. text
  319. @a0 16
  320.  
  321. /******************************************************************************
  322.  
  323. $Id: mice.c,v 1.2.1.1 2002/03/26 22:04:17 jason Exp jason $
  324.  
  325. $Log: mice.c,v $
  326.  * Revision 1.2.1.1  2002/03/26  22:04:17  jason
  327.  * Added RCS Header
  328.  *
  329.  * Revision 1.2.1.1  2002/03/26  22:00:51  jason
  330.  * RCS/agl.h,v
  331.  *
  332.  
  333. ******************************************************************************/
  334.  
  335.  
  336. @
  337.  
  338.  
  339. 1.2.1.2
  340. log
  341. @check for NOT_EXTERN
  342. @
  343. text
  344. @d4 1
  345. a4 1
  346. $Id: mice.c,v 1.2.1.1 1994/03/29 05:41:32 jason Exp jason $
  347. a6 3
  348.  * Revision 1.2.1.1  1994/03/29  05:41:32  jason
  349.  * Added RCS Header
  350.  *
  351. a16 1
  352. #ifndef NOT_EXTERN
  353. a17 1
  354. #endif
  355. @
  356.  
  357.  
  358. 1.2.1.3
  359. log
  360. @added copyright
  361. @
  362. text
  363. @d1 1
  364. d4 1
  365. a4 4
  366. Copyright © 1994 Jason Weber
  367. All Rights Reserved
  368.  
  369. $Id: mice.c,v 1.2.1.2 1994/11/16 06:25:25 jason Exp jason $
  370. a6 3
  371.  * Revision 1.2.1.2  1994/11/16  06:25:25  jason
  372.  * check for NOT_EXTERN
  373.  *
  374. @
  375.  
  376.  
  377.  
  378.  
  379.  
  380.  
  381.  
  382.  
  383.  
  384.  
  385.  
  386.  
  387.  
  388.  
  389.  
  390.  
  391.  
  392.  
  393.  
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.  
  401.  
  402.  
  403.  
  404.  
  405.  
  406.  
  407.  
  408.  
  409.  
  410.  
  411.  
  412.  
  413.  
  414.  
  415.  
  416.  
  417.  
  418.  
  419.  
  420.  
  421.  
  422.  
  423.  
  424.  
  425.  
  426.  
  427.  
  428.  
  429.  
  430.  
  431.  
  432.  
  433.  
  434.  
  435.  
  436.  
  437.  
  438.  
  439.  
  440.  
  441.  
  442.  
  443.  
  444.  
  445.  
  446.  
  447.  
  448.  
  449.  
  450.  
  451.  
  452.  
  453.  
  454.  
  455.  
  456.  
  457.